#pragma once

#include "WinLock.h"

class ckfifo
{
public:
	explicit ckfifo(unsigned int size);
	~ckfifo();

	bool init();

	unsigned int fifo_put(const unsigned char *buf, unsigned int len);
	unsigned int fifo_get(unsigned char *buf, unsigned int len);

	inline unsigned int fifo_len() 
	{
		return m_in - m_out;
	}
	inline void fifo_reset()
	{
		m_out = m_in = 0; 
	}

private:
	unsigned int roundpower_of_2(unsigned int len);

private:
	unsigned char *m_buf;
	unsigned int m_in;
	unsigned int m_out;
	unsigned int m_size;

	WinLock m_lock;
};